package mud;

/** The common direction that one can move */
public enum Direction {
    
    /** Direction */
    NORTH("N"),
    
    /** Direction */
    SOUTH("S"),
    
    /** Direction */
    EAST("E"),
    
    /** Direction */
    WEST("W"),
    
    /** Direction */
    NORTHEAST("NE"),
    
    /** Direction */
    NORTHWEST("NW"),
    
    /** Direction */
    SOUTHEAST("SE"),
    
    /** Direction */
    SOUTHWEST("SW"),
    
    /** Direction */
    UP("U"),
    
    /** Direction */
    DOWN("D");
    
    /** the shorthand version of the direction */
    private final String abreviation;

    /**
     * @param abreviation the shorthand version of the direction
     */
    private Direction(String abreviation) {
        this.abreviation = abreviation;
    }

    /**
     * Returns the direction corresponding to the given string
     * @param input the string to match 
     * @return the corresponding direction, or null
     */
    public static Direction fromString(String input) {
        for (Direction direction : values()) {
            if (direction.name().equalsIgnoreCase(input) ||
                direction.getAbreviation().equalsIgnoreCase(input)) {
                return direction;
            }
        }
        return null;
    }
    
    /**
     * @return the shorthand version of the direction
     */
    public String getAbreviation() {
        return abreviation;
    }
}
